package si.dejan.picflip.controller.commands
{
	import air.update.ApplicationUpdaterUI;
	import air.update.events.UpdateEvent;
	
	import flash.events.ErrorEvent;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class Update extends SimpleCommand implements ICommand
	{
		// this takes 20mb of memory
		private var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI();
		
		override public function execute(notification:INotification):void
		{
			// update code
			// url-xml http://dejan.zaba.si/PicFlip/update.xml
			// url-app http://dejan.zaba.si/PicFlip/PicFlip.air
			
			appUpdater.updateURL = "http://dejan.zaba.si/PicFlip/update.xml";
			appUpdater.isCheckForUpdateVisible = false;
			appUpdater.addEventListener(UpdateEvent.INITIALIZED, handleInitialized);
			appUpdater.addEventListener(ErrorEvent.ERROR, handleError);
			appUpdater.initialize();
		}
		
		private function handleInitialized(event:UpdateEvent):void
		{
			appUpdater.checkNow();
		}
		
		private function handleError(event:ErrorEvent):void
		{
			trace("error");
		}
	}
}